package cn.lovezsm.bjcjbase.util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

public class WebUtils {




    public static File transMultipartFile(MultipartFile multipartFile) throws IOException {
        String fileName = multipartFile.getOriginalFilename();
        String prefix = fileName.substring(fileName.lastIndexOf("."));
        final File ans = File.createTempFile(UUIDGenerator.getUUID(),prefix);
        multipartFile.transferTo(ans);
        return ans;
    }

    public static void deleteFile(File... files) {
        for (File file : files) {
            if (file.exists()) {
                file.delete();
            }
        }
    }

    public static class UUIDGenerator {
        /**
      * 获取32位UUID字符串
      * @return
      */
        public static String getUUID() {
            return UUID.randomUUID().toString().replaceAll("-", "");
        }

        /**
      * 获取32位UUID大写字符串
      * @return
      */
        public static String getUpperCaseUUID() {
            return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
        }


    }

}
